import { defineStore } from 'pinia'
import { getPopularSearchApi } from '@/api/search'
import type { searchData } from '@/api/modules/search'
import { flatten } from 'lodash'

const useSearchStore = defineStore('searchStore', {
    state: () => {
        return {
            searchData: {} as searchData,
            errorIsShow: true
        }
    },
    actions: {
        async getPopular() {
            try {
                this.searchData = await getPopularSearchApi()
            } catch (e) {
                return Promise.reject('获取失败')
            }
        },
        getErrorIsShow(flag: boolean) {
            this.errorIsShow = flag
        },
    },

    getters: {
        defaultKeyword: (state) => {
            return state.searchData.defaultKeyword
        },
        hotKeywordVOList: (state) => {
            return state.searchData.hotKeywordVOList
        }
    }
})

export default useSearchStore